home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8313 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  66 lines

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Pure Virtual Destructor Question
  5. Date: 16 Feb 1996 19:26:48 GMT
  6. Organization: Borland International
  7. Message-ID: <4g2lpo$f81@druid.borland.com>
  8. References: <4fas7a$7ns@comet2.magicnet.net> <4fecq0$k4e@news4.digex.net> <rcauvin-0902960901140001@quadostimpy.natinst.com> <4fp5r2$dm2@news4.digex.net>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <4fp5r2$dm2@news4.digex.net>, ell@access1.digex.net says...
  15. >
  16. >Roger L. Cauvin (rcauvin@natinst.com) wrote:
  17. >: In article <4fecq0$k4e@news4.digex.net>, ell@access4.digex.net (Ell) wrote:
  18. >: 
  19. >: >It is _illegal_ to logically, or physically "define" a pure
  20. >: > virtual function in the class it is "declared" in.  A pure virtual should
  21. >: > only be defined in classes derived from the class where the pure virtual
  22. >: > is declared.  Only derived classes should "do some destructor stuff".
  23. >: 
  24. >: Actually, it is acceptable to define a pure virtual function in the class
  25. >: in which it is declared.  Pure virtual destructors are a special case;
  26. >: they MUST be defined in the class in which they are declared.
  27. >
  28. >Yes, a pure virtual dtor MUST be _defined_ as a member of the class it is
  29. >declared in.  As dtors are not inherited by derived classes, the only
  30. >place to override the pure virtual declaration for a class is as a member
  31. >of the class (though it must actually be defined outside of the class
  32. >declaration).  
  33. >
  34.  
  35. The issue is not whether you have a place to override it. The issue is whether 
  36. it is actually called.
  37.  
  38. >Still a class with a single pure virtual declaration, such as a pure
  39. >virtual dtor declaration is considered to be 'abstract' even with the
  40. >"outside of class declaration" definition of the pure virtual dtor. 
  41.  
  42. Yes, but this is just a specific example of the general rule that any class 
  43. with a pure virtual function is abstract, even if you provide a definition for 
  44. that function.
  45.  
  46. void Base
  47. {
  48. public:
  49.     virtual void f() = 0;
  50. };
  51.  
  52. void Derived : public Base
  53. {
  54. public:
  55.     void f() { Base::f(); }
  56. };
  57.  
  58. void Base::f()
  59. {
  60. }
  61.  
  62. A definition of Base::f is required because it is called. Base is still an 
  63. abstract class, because it contains a pure virtual function.
  64.     -- Pete
  65.  
  66.